<?php 
class Model_DAO_Content
{
    public function lists()
    {
        global $dbconfig;
        $listcontent = array();
        try
        {
            $sql = "select * from ".table_prefix("content");
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_row() != 0)
            {
                $arrs = $dbconfig->fetch_array();
                foreach($arrs as $arr)
                {
                    $content = CreateObject("Model_Entity_Content");
                    $content->id = $arr["id"];
                    $content->idcategory = $arr["idcategory"];
                    $content->title = $arr["title"];
                    $content->introtext = $arr["introtext"];
                    $content->fulltext = $arr["fulltext"];
                    $content->order = $arr["order"];
                    $content->create_by = $arr["create_by"];
                    $content->updated = $arr["updated"];
                    $content->start_date = $arr["start_date"];
                    $content->end_date = $arr["end_date"];
                    $content->is_comment = $arr["is_comment"];
                    $content->view = $arr["view"]; 
                    $content->status = $arr["status"];       
                    
                    $listcontent[] = $content;
                }   
            }
            else
            {
                $listcontent = NULL;
            }
            $dbconfig->close();
            return $listcontent;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $listcontent;
        }
    }
    
    public function get($id)
    {
        global $dbconfig;
        $content = NULL;
        try
        {
            $sql = "select * from ".table_prefix("content")." where id='".$dbconfig->sqlQuote($id)."'";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_row() != 0)
            {
                $arr = $dbconfig->fetch_array();
                $arr = $arr[0];
                $content = CreateObject("Model_Entity_Content");
                 $content->id = $arr["id"];
                 $content->idcategory = $arr["idcategory"];
                    $content->title = $arr["title"];
                    $content->order = $arr["order"];
                    $content->introtext = $arr["introtext"];
                    $content->fulltext = $arr["fulltext"];
                    $content->create_by = $arr["create_by"];
                    $content->updated = $arr["updated"];
                    $content->start_date = $arr["start_date"];
                    $content->end_date = $arr["end_date"];
                    $content->is_comment = $arr["is_comment"];
                    $content->view = $arr["view"]; 
                    $content->status = $arr["status"];      
                
            }
            else
            {
                $content = NULL;
            }
            $dbconfig->close();
            return $content;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $content;
        }
    }
    
    public function create($content)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "insert into ".table_prefix("content")."(idcategory,title,title,order,create_by,updated,start_date,end_date,is_comment,view,status) values ('".$dbconfig->sqlQuote($content->idcategory)."','".$dbconfig->sqlQuote($content->title)."','".$dbconfig->sqlQuote($content->content)."','".$dbconfig->sqlQuote($content->order)."','".$dbconfig->sqlQuote($content->create_by)."','".$dbconfig->sqlQuote($content->updated)."','".$dbconfig->sqlQuote($content->start_date)."','".$dbconfig->sqlQuote($content->end_date)."','".$dbconfig->sqlQuote($content->is_comment)."','".$dbconfig->sqlQuote($content->view)."','".$dbconfig->sqlQuote($content->status)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
    
    public function delete($id)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "delete from ".table_prefix("content")." where id = '".$dbconfig->sqlQuote($content->id)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
    
    public function update($content)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "update ".table_prefix("content")." set title='".$dbconfig->sqlQuote($acount->title)."',id='".$dbconfig->sqlQuote($content->idcategory)."',content ='".$dbconfig->sqlQuote($content->content)."', = order ='".$dbconfig->sqlQuote($content->order)."',create_by ='".$dbconfig->sqlQuote($content->create_by)."',updated = '".$dbconfig->sqlQuote($content->updated)."',start_date = '".$dbconfig->sqlQuote($content->start_date)."',end_date ='".$dbconfig->sqlQuote($content->end_date)."',is_comment ='".$dbconfig->sqlQuote($content->is_comment)."',view='".$dbconfig->sqlQuote($content->view)."',status ='".$dbconfig->sqlQuote($content->status)." where id ='".$dbconfig->sqlQuote($content->id)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
}
?>